/**
 * Package name:indi.yangshenhui.util
 * File name:PropertiesUtil.java
 * Date:2016年8月12日-上午9:44:26
 * feiniu.com Inc.Copyright (c) 2013-2015 All Rights Reserved.
 *
 */
package indi.yangshenhui.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @ClassName PropertiesUtil
 * @Description 读取根目录下的配置文件
 * @date 2016年8月12日 上午9:44:26
 * @author shenhui.yang
 * @version 1.0.0
 *
 */
public class PropertiesUtil {
	private static final Logger LOGGER = LoggerFactory.getLogger(PropertiesUtil.class);

	private PropertiesUtil() {
	}

	/**
	 * 最优单例模式
	 * 
	 * @ClassName SingletonHolder
	 * @Description
	 * @date 2016年8月12日 上午9:53:09
	 * @author shenhui.yang
	 * @version 1.0.0
	 *
	 */
	private static class SingletonHolder {
		private static final PropertiesUtil INSTANCE = new PropertiesUtil();

		private SingletonHolder() {
		}
	}

	public static PropertiesUtil getInstance() {
		return SingletonHolder.INSTANCE;
	}

	/**
	 * 只能读取classPath下配置文件 getProperties
	 * 
	 * @param file
	 * @return Properties
	 * @exception @since
	 *                1.0.0
	 */
	public Properties getProperties(String file) {
		Properties properties = new Properties();
		InputStream inputStream = null;
		try {
			inputStream = PropertiesUtil.class.getClassLoader().getResourceAsStream(file);
			properties.load(inputStream);
		} catch (IOException e) {
			LOGGER.error("读取classPath目录配置文件[" + file + "]异常:" + e.getMessage(), e);
		} finally {
			if (inputStream != null) {
				try {
					inputStream.close();
				} catch (IOException e) {
				}
			}
		}
		return properties;
	}

}
